package com.object.handler;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.object.model.UserInfo;

public class ServerHandler extends IoHandlerAdapter {
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Override
	public void messageReceived(IoSession session, Object message) throws Exception {
		UserInfo ui = (UserInfo)message; //我们已设定了服务器解析消息的规则是以UserInfo对象为单位进行传输
		logger.info("收到客户机发来的用户名：" + ui.getName());
		session.write(new UserInfo(ui.getName() + "==>>是个神秘的人"));
	}
	
	@Override
	public void sessionOpened(IoSession session) throws Exception{
		logger.info("InComing Client：" + session.getRemoteAddress());
	}
}